#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
  int *bp;
  int *sp;
  int i;
  int *next;
}Stack;

typedef struct
{
  int eax;
  int ebx;
  int ecx;
  int edx;
}CPU;

typedef struct
{
  int i;
  void *func;
  char *functype;
}SystemCall;

typedef int (*fadd)(int ,int);
int add(int a,int b)
{
  return a + b;
}

void Stub(int SystemNum,int *various,CPU *cpu,SystemCall *os)
{
  switch(SystemNum)
    {
    case 0:
      cpu -> eax = ((fadd)os[0].func)(various[0],various[1]);
    }
}

void dump(CPU *cpu)
{
  printf("Dump CPU state");
  printf("\n");
  printf("%d\n",cpu -> eax);
  printf("%d\n",cpu -> ebx);
  printf("%d\n",cpu -> ecx);
  printf("%d\n",cpu -> edx);
}

int main(){
  SystemCall *os = (SystemCall *) malloc(10*sizeof(SystemCall));
  memset(os,0,10*sizeof(SystemCall));
  CPU *cpu =  (CPU *) malloc(sizeof(CPU));
  memset(cpu,0,sizeof(CPU));
  

  os[0].i = 0;
  os[0].func  = (fadd)add;
  int a[] = {1,2};


  Stub(0,a,cpu,os);

  dump(cpu);
  
  return 0;
}
